package com.msb.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.msb.mall.product.vo.OrderItemSpuInfoVO;
import com.msb.mall.product.vo.spuinfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.msb.mall.product.entity.SpuInfoEntity;
import com.msb.mall.product.service.SpuInfoService;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;



/**
 * spu信息
 *
 * @author xxf
 * @email 1983752950@qq.com
 * @date 2022-09-10 22:42:30
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;


    //http://localhost:8070/app/product/spuinfo/11/up
    @PostMapping("{spuId}/up")
    public R up(@PathVariable("spuId") Long spuId){
        spuInfoService.up(spuId);

        return R.ok();
    }


    @RequestMapping("/getOrderItemSpuInfoBySpuId/{spuIds}")
    public List<OrderItemSpuInfoVO> getOrderItemSpuInfoBySpuId(@PathVariable("spuIds") Long[] spuIds){
      List<OrderItemSpuInfoVO> itemSpuInfoVOS= spuInfoService.getOrderItemSpuInfoBySpuId(spuIds);

        return itemSpuInfoVOS;
    }


    /**
     * 列表
     */
    //http://localhost:8070/app/product/spuinfo/list?t=1665128940468&status=&key=&brandId=0&catelogId=0&page=1&limit=10
    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        //PageUtils page = spuInfoService.queryPage(params);
        PageUtils page=spuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions("product:spuinfo:info")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    // http://localhost:8070/app/product/spuinfo/save
    @RequestMapping("/save")
   // @RequiresPermissions("product:spuinfo:save")
    public R save(@RequestBody spuinfoVO spuinfoVO){
		//spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuinfoVO);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:spuinfo:update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("product:spuinfo:delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
